package com.example.springbootlocal.common;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;

import java.util.List;
import java.util.Objects;

/**
 * @author X.I.O
 * @title: JsonUtils
 * @projectName spring-boot-local
 * @description: TODO
 * @date 2021/11/9 14:42
 */
public class JsonUtils {

    public static <T> String formartObjectToString(List<T> tList){
        return JSON.toJSONString(tList);
    }

    public static <T> List<T> formartListFromString(String str){
        return (List<T>) JSON.parse(str);
    }


    /**
     * 输出带格式的json格式
     * @param object
     * @param <T>
     * @return
     */
    public static <T> String formartString(Object object){
        String pretty = JSON.toJSONString(object, SerializerFeature.PrettyFormat, SerializerFeature.WriteMapNullValue,
                SerializerFeature.WriteDateUseDateFormat);
        return pretty;
    }
}
